package com.cgah

class ListingFeedController {
/*
    def title;
    def description;
    def link;
*/
    def listingService

    def index = {
        redirect(action: "feed")
    }

    def feed = {
        params.max = Math.min(params.max ? params.int('max') : Constants.MAX_TO_DISPLAY, 100)

        if (!params.sort) params.sort = "createdDateTime"
        if (!params.order) params.order = "desc"
        if (!params.offset) params.offset = 0;

        def zpath = request.getRequestURL().substring(0, (request.getRequestURL().length() - request.getRequestURI().length()) + request.contextPath.length())
        render(feedType: "rss") {
            title = "Active Listings"
            link = zpath + "/listingFeed/feed"
            description = "Current active listings"
            listingService.list(params).each() { listing ->
                entry(listing.title()) {
                   link = zpath + "/listing/show/${listing.id}"
                   listing.feedContent()
                }
            }
        }
    }

}
